package com.acwing.partition43;

import java.io.*;
import java.util.Arrays;

/**
 * @author rkc
 * @date 2022/6/17 17:21
 */
public class AC4275Dijkstra序列 {

    private static final int N = 1010, INF = 0x3f3f3f3f;
    private static int[][] g = new int[N][N];
    private static int[] path = new int[N], dist = new int[N];
    private static boolean[] st = new boolean[N];
    private static int n, m;

    private static StreamTokenizer tokenizer = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    private static PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        n = nextInt(); m = nextInt();
        for (int i = 0; i < N; i++) Arrays.fill(g[i], INF);
        for (int i = 0; i < m; i++) {
            int a = nextInt(), b = nextInt(), c = nextInt();
            g[a][b] = g[b][a] = c;
        }
        int k = nextInt();
        while (k-- > 0) {
            for (int i = 1; i <= n; i++) path[i] = nextInt();
            if (check()) writer.println("Yes");
            else writer.println("No");
        }
        writer.flush();
    }

    private static boolean check() {
        for (int i = 0; i < N; i++) {
            dist[i] = INF;
            st[i] = false;
        }
        dist[path[1]] = 0;
        for (int i = 1; i <= n; i++) {
            int u = path[i];
            //检查当前节点是否是集合外最近的点
            for (int j = 1; j <= n; j++) {
                if (!st[j] && dist[j] < dist[u]) {
                    return false;
                }
            }
            st[u] = true;
            for (int j = 1; j <= n; j++) {
                dist[j] = Math.min(dist[j], dist[u] + g[u][j]);
            }
        }
        return true;
    }

    private static int nextInt() throws IOException {
        tokenizer.nextToken();
        return (int) tokenizer.nval;
    }
}
